package com.bestdreamer.stream;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class ListMapStreamTest {


    public static void main(String[] args) {
        List<Map<String,String>> mapList = new ArrayList<>();
        HashMap<String,String> map1 = new HashMap<String,String>(){
            {
                put("name","张三");
                put("age","14");
            }
        };

        HashMap<String,String> map2 = new HashMap<String,String>(){
            {
                put("name","李四");
                put("age","15");
            }
        };

        HashMap<String,String> map3 = new HashMap<String,String>(){
            {
                put("name","王五");
                put("age","15");
            }
        };
        mapList.add(map1);
        mapList.add(map2);
        mapList.add(map3);
        System.out.println(mapList);

        Map<String,String> mapResult =  mapList.stream().collect(Collectors.toMap(t->t.get("name"),t->t.get("age"),(a,b)->b));

        System.out.println(mapResult);


    }
}
